package com.ehotting.edsta.circuitDesign.service.impl;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import com.ehotting.edsta.circuitDesign.domain.CodeAndIdType;
import com.ehotting.edsta.circuitDesign.enums.CodeDataTypeEnum;
import com.ehotting.edsta.circuitDesign.domain.EsCircuitCodeDataTemplate;
import com.ehotting.edsta.circuitDesign.mapper.EsCircuitCodeDataTemplateMapper;
import com.ehotting.edsta.circuitDesign.service.IEsCircuitCodeDataTemplateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


/**
 * 电路属性参数模板Service业务层处理
 * 
 * @author edsta
 * @date 2023-07-24
 */
@Service
public class EsCircuitCodeDataTemplateServiceImpl implements IEsCircuitCodeDataTemplateService{

    @Autowired
    private EsCircuitCodeDataTemplateMapper esCircuitCodeDataTemplateMapper;

    /**
     * 查询电路属性参数模板
     * 
     * @param id 电路属性参数模板主键
     * @return 电路属性参数模板
     */
    @Override
    public EsCircuitCodeDataTemplate selectEsCircuitCodeDataTemplateById(Long id)
    {
        return esCircuitCodeDataTemplateMapper.selectEsCircuitCodeDataTemplateById(id);
    }

    /**
     * 查询电路属性参数模板列表
     * 
     * @param esCircuitCodeDataTemplate 电路属性参数模板
     * @return 电路属性参数模板
     */
    @Override
    public List<EsCircuitCodeDataTemplate> selectEsCircuitCodeDataTemplateList(EsCircuitCodeDataTemplate esCircuitCodeDataTemplate)
    {
        return esCircuitCodeDataTemplateMapper.selectEsCircuitCodeDataTemplateList(esCircuitCodeDataTemplate);
    }

    /**
     * 新增电路属性参数模板
     * 
     * @param esCircuitCodeDataTemplate 电路属性参数模板
     * @return 结果
     */
    @Override
    public int insertEsCircuitCodeDataTemplate(EsCircuitCodeDataTemplate esCircuitCodeDataTemplate)
    {
        return esCircuitCodeDataTemplateMapper.insertEsCircuitCodeDataTemplate(esCircuitCodeDataTemplate);
    }

    /**
     * 修改电路属性参数模板
     * 
     * @param esCircuitCodeDataTemplate 电路属性参数模板
     * @return 结果
     */
    @Override
    public int updateEsCircuitCodeDataTemplate(EsCircuitCodeDataTemplate esCircuitCodeDataTemplate)
    {
        return esCircuitCodeDataTemplateMapper.updateEsCircuitCodeDataTemplate(esCircuitCodeDataTemplate);
    }

    /**
     * 批量删除电路属性参数模板
     * 
     * @param ids 需要删除的电路属性参数模板主键
     * @return 结果
     */
    @Override
    public int deleteEsCircuitCodeDataTemplateByIds(Long[] ids)
    {
        return esCircuitCodeDataTemplateMapper.deleteEsCircuitCodeDataTemplateByIds(ids);
    }

    /**
     * 删除电路属性参数模板信息
     * 
     * @param id 电路属性参数模板主键
     * @return 结果
     */
    @Override
    public int deleteEsCircuitCodeDataTemplateById(Long id)
    {
        return esCircuitCodeDataTemplateMapper.deleteEsCircuitCodeDataTemplateById(id);
    }


    /**
     * 根据电路类型ID查找
     * @param circuitTypeId
     * @return
     */
    public List<EsCircuitCodeDataTemplate> selectByTypeAndCircuitTypeId(CodeDataTypeEnum type, Long circuitTypeId){
        EsCircuitCodeDataTemplate param = new EsCircuitCodeDataTemplate();
        param.setCircuitTypeId(circuitTypeId);
        param.setType(type);
        return  selectEsCircuitCodeDataTemplateList(param);

    }


    @Override
    public Map<String, Long> selectByCircuitTypeIdReturnMap(Long circuitTypeId) {
        List<CodeAndIdType> map = esCircuitCodeDataTemplateMapper.selectByCircuitTypeIdReturnMap(circuitTypeId);
        Map<String, Long> collect = map.stream().collect(Collectors.toMap(CodeAndIdType::getCode, CodeAndIdType::getId));
        return collect;
    }


}
